/**
 * @file 照片配置
 * @author 李刚
 * @date 2021-09-25 15:24:11
 */

var treeGrid = null, tableId = 'order_picture_product_table';
layui.define(['element', 'layer', 'upload', 'form', 'step', 'zmnSelect', 'zmnOmsSelect', "treeTable", '$http', 'previewer'
    , 'oms_conf_attachment_orderPicture_channel'
], function (exports) {
    let $ = layui.$;
    let layer = layui.layer;
    let upload = layui.upload;
    let form = layui.form;
    let step = layui.step;
    let zmnSelect = layui.zmnSelect;
    let zmnOmsSelect = layui.zmnOmsSelect;
    let treeTable = layui.treeTable;
    var zmnUtils = layui.zmnUtils;
    let $http = layui.$http;
    var previewer = layui.previewer;
    let zmnApp = layui.zmnApp;
    let timestamp = new Date().getTime();
    let channelInfo = layui.oms_conf_attachment_orderPicture_channel
    // 总提交参数
    let submitParam = {}

    window.sessionStorage.setItem("list_channel_table_data", JSON.stringify(json.listChannel));//将json字符串存入localStorage
    // 初始化流程组件（step）
    let process = [{title: '基本信息'}, {title: '渠道配置'}, {title: '城市配置'}, {title: '产品配置'}];
    step.render({
        elem: '#stepForm',
        filter: 'stepForm',
        width: '100%',
        stepWidth: '80%',
        height: '700px',
        stepItems: process,
    });
    /*********************************************第一个页面初始化（基本信息）***********************************************************/
    // 照片类型下拉组件
    zmnOmsSelect.selectConfOrderAttachmentCategory('categId', {
        isRadio: true,
        selectedValues: json.param.categId === null ? null : json.param.categId,
        tips: "全部",   //默认提示
        type: 1,
        page: {enable: true, remote: true, pageSize: 2000, required: true},
        remote: {
            events: {
                extendParams: function () {
                    return {status: 2}
                }
            }
        }
    });
    // 业务类型下拉组件
    zmnSelect.selectlServBizUnits({
        bizTypeSelectId: 'bizType',
    }, {
        bizTypeSelectId: {
            selectedValues: json.param.bizType
        }
    });
    //  图片上传方法
    let indexUploadImags;

    function uploaderImage(elemId, valueId) {
        upload.render({
            elem: '#' + elemId
            , exts: 'jpg|png|jpeg'
            , acceptMime: 'image/*'
            , accept: 'images'
            , url: '/conf/attachment/orderPicture/uploader?timestamp=' + timestamp + '&elemId=' + elemId
            , size: 5120
            , beforeSend: function (obj) {
                indexUploadImags = layui.layer.load(1, {
                    shade: [0.5, '#DBDBDB']
                });
            }
            , done: function (res) {
                if (res.statusBool) {
                    let data = res.data;
                    $("#" + valueId).val(data);
                    $("#" + valueId + "s").attr("src", data).attr("style", "width: 0;height: 0");
                    reLoadImage(elemId, data);
                } else {
                    layer.msg(res.message)
                }
                layui.layer.close(indexUploadImags);
            }
        });
    }
    // 获取照片并显示
    function reLoadImage(elemId, value, valueId) {
        zmnUploadUtil.reLoadImage($, elemId, value, valueId);
        let next = $("#" + elemId).next();
        $(next).attr("style", "visibility:hidden !important");
    }
    // 初始化基本信息页面
    function initPage() {
        // 初始化图片预览器
        previewer.initTextList('.container-images');

        uploaderImage("egImgSrc", "egSrc");
        // 点击删除图片
        $(document).on('click', '.btn-delete', function () {
            let $uploadDiv = $(this).parent().prev().prev();
            $uploadDiv.attr("style", "");
            $uploadDiv.find(".layui-upload-drag").attr("style", "");
            $uploadDiv.find("i").attr("style", "");
            $uploadDiv.find("p").attr("style", "");
            $uploadDiv.find(":hidden").val("");
            $uploadDiv.find("img").prop("src", "");
        });
        // 点击放大
        $(document).on('click', '.btn-review', function () {
            if (!$(this).parent().prev().prev().find("input").eq(0).val()) {
                layer.msg("请上传对应图片再预览");
                return;
            }
            let $container = $(this).parent().prev().prev().find("img").eq(0);
            $container.viewer().on('hide', function () {
                $container.viewer('destroy');
            });
            let index = $(this).index();
            $container.viewer('view', index);
        });

        reLoadImage('egImgSrc', json.param.egSrc, 'egSrc');
        $("#egSrc").val(json.param.egSrc);
        $("#egImgSrcShow").attr("src", json.param.egSrc).attr("style", "width: 0;height: 0");

    }
    // 校验
    function verify(data) {
        if (!data.field.categId) {
            layer.msg("请选择照片类型！", {"icon": 2});
            return false;
        }
        var reg = /^[0-9]\d*$/;//正整数
        if (!reg.test(data.field.sort)) {
            layer.msg("请输入正整数！", {"icon": 2});
            return false;
        }

        if (!data.field.bizType) {
            layer.msg("请选择应用业务类型！", {"icon": 2});
            return false;
        }
        if (!data.field.needReview) {
            layer.msg("请选择后台是否审核！", {"icon": 2});
            return false;
        }
        if (!data.field.autoAudit) {
            layer.msg("请选择自动审核！", {"icon": 2});
            return false;
        }
        if (!data.field.mustUpload) {
            layer.msg("请选择是否必传！", {"icon": 2});
            return false;
        }
        return true;
    }

    initPage()
    // 基本信息提交
    form.on('submit(zmn-base-info-form-submit)', function (data) {
        let submit = verify(data)
        console.log("dto", data)
        if (submit) {
            submitParam = data.field
            console.log("dto", submitParam)
            step.next('#stepForm');
        }
    });
    /*********************************************第一个页面初始化（渠道配置）***********************************************************/
    let allChannel = json.param.allChannel || 1;
    let excludeType = 1
    channelInfo.tableChannel()
    form.on('switch(allChannel)', function (data) {
        if (this.checked) {
            allChannel = 3
            $('.excludeType').prop("checked", false);
            form.val("order_picture_channel-form", 'excludeType');
            window.sessionStorage.setItem("switch_allChannel", 1)
        } else {
            allChannel = excludeType
            console.log("allChannel")
            window.sessionStorage.setItem("switch_allChannel", 2)
        }
    });
    form.on('switch(excludeType)', function (data) {
        if (this.checked) {
            allChannel = 2
            excludeType = 2
            $('.allChannel').prop("checked", false);
            window.sessionStorage.setItem("switch_allChannel", 2)
            form.val("order_picture_channel-form", 'allChannel');
        } else {
            allChannel = 1
            excludeType = 1
            window.sessionStorage.setItem("switch_allChannel", 2)
        }
    });
    $('body').on('click', '#btn-skip-channel-page', function () {
        var url = '/conf/attachment/orderPicture/listChannel.action?includeChannel=' + $("#limitChannel").val();
        let data = {
            title: '',
            shade: 0.8,
            maxmin: false,
            resize: false,
            closeBtn: 1,
        };
        zmnLayUtil.openIframeCustom(layer, url, data);
        return false;
    });
    // 渠道信息提交
    form.on('submit(order_picture_channel-submit)', function (obj) {
        let json = window.sessionStorage.getItem("list_channel_table_data")
        let list_channel_table_data = JSON.parse(json)
        if (allChannel === 3) {
            submitParam.confOrderAttachmentChannelDIOS = []
        } else {
            if (list_channel_table_data.length === 0) {
                layer.msg("请选择是否排除或使用的渠道信息！", {"icon": 2});
                return false;
            }
            submitParam.confOrderAttachmentChannelDIOS = list_channel_table_data
        }
        submitParam.allChannel = allChannel
        step.next('#stepForm');
    });
    /*********************************************第一个页面初始化（城市配置）***********************************************************/

    var oldData = {id: json.param.id}
    var allCity = json.param.allCity || false;

    if (json.listCity && !allCity) {
        let province_checkbox_startWith = "provinceIds[";
        let city_checkbox_startWith = "cityIds[";
        let checkbox_endWith = "]";

        $.each(json.listCity, function (i, item) {
            let cityId = item.cityId;
            let provinceId = item.provinceId;

            // 本省下所有城市是否全选
            var proviceCitiesAll = null;
            if (json.proviceAllCitiesNumber != null && json.proviceAllCitiesNumber != null && json.proviceSelectedCitiesNumber[item.provinceId]
                && json.proviceAllCitiesNumber[item.provinceId] == json.proviceSelectedCitiesNumber[item.provinceId]) {
                proviceCitiesAll = true;
            }
            if (proviceCitiesAll) {
                var attr = province_checkbox_startWith + provinceId + checkbox_endWith;
                //本省份下面的所有城市勾上
                $('.batch-city-all-checkbox[parentid=' + provinceId + ']').prop("checked", true);
                oldData[attr] = true;
            } else {
                var attr = city_checkbox_startWith + provinceId + '-' + cityId + checkbox_endWith;
                oldData[attr] = true;
            }
        });
    } else {
        //全国下面的所有省份和所有城市勾上
        $(".batch-city-all-checkbox").prop("checked", true);
    }
    form.val("order_picture_city", oldData);
    form.on('checkbox(batch-city-checkbox-filter1)', function (data) {
        debugger
        if (data.elem.checked) {
            allCity = true
            $(".batch-city-all-checkbox").prop("checked", true);
        } else {
            allCity = false
            $(".batch-city-all-checkbox").prop("checked", false);
        }
        form.val("order_picture_city");
    });
    form.on('checkbox(batch-city-checkbox-filter2)', function (data) {
        let value = data.value;
        let selector = '.batch-city-all-checkbox[parentid=' + value + ']';
        if (data.elem.checked) {
            allCity = false
            $(selector).prop("checked", true);
            checkNationwide(data.elem);
        } else {
            allCity = false
            $(selector).prop("checked", false);
            $('.batch-nationwide-checkbox').prop("checked", false);
        }
        form.val("order_picture_city");
    });
    form.on('checkbox(batch-city-checkbox-filter3)', function (data) {
        var parentId = $(data.elem).attr("parentid");
        let selector = '.batch-city-all-checkbox[value=' + parentId + ']';
        if (data.elem.checked) {
            allCity = false
            var checked = true;
            var siblings = $(data.elem)
                .parents('.layui-input-block-level2')
                .find('input.batch-city-checkbox');
            siblings.each(function () {
                let item = this;
                if (!$(item).prop("checked")) {
                    checked = false;
                    return false;
                }
            });
            $(selector).prop("checked", checked);
            if (!checked) {
                $('.batch-nationwide-checkbox').prop("checked", false);
            } else {
                checkNationwide($(selector));
            }
        } else {
            allCity = false
            $(selector).prop("checked", false);
            $('.batch-nationwide-checkbox').prop("checked", false);
        }
        form.val("order_picture_city");
    });

    function checkNationwide(elem) {
        var finds = $(".batch-province-checkbox");
        var checked = true;
        finds.each(function () {
            var item = this;
            if (!$(item).prop("checked")) {
                checked = false;
                return false;
            }
        });
        $('.batch-nationwide-checkbox').prop("checked", checked);
    }

    // 城市信息提交
    form.on('submit(order_picture_city-submit)', function (obj) {

        let data = obj.field;
        data.promId = obj.field.promId;
        let city_checkbox_startWith = "cityIds[";
        let cityList = new Array();
        $.each(data, function (attr, value) {
            let confOrderAttachmentCity = new Object();
            let cityId = attr.startsWith(city_checkbox_startWith);
            if (cityId) {
                let city = attr.replace(city_checkbox_startWith, '').replace(']', '').split("-")
                confOrderAttachmentCity.provinceId = city[0];
                confOrderAttachmentCity.cityId = city[1];
                cityList.push(confOrderAttachmentCity)
            }
        });
        if (cityList.length === 0) {
            layer.msg("请先选择城市信息", {icon: 2});
            return false;
        }
        if (allCity) {
            submitParam.allCity = true
            submitParam.confOrderAttachmentCities = []
        } else {
            submitParam.allCity = false
            submitParam.confOrderAttachmentCities = cityList
        }
        console.log("submitParam order_picture_city-submit", submitParam)
        step.next('#stepForm');
    });

    /*********************************************第一个页面初始化（产品）***********************************************************/
    var serverClasscheck;
    var oneClasscheck;
    var twoClasscheck;

    let serverClassTable = treeTable.render({
        elem: '#' + tableId,
        tree: {
            iconIndex: 0,  // 折叠图标显示在第几列
            idName: 'id',  // 自定义id字段的名称
            pidName: 'parentId',  // 自定义标识是否还有子节点的字段名称
            haveChildName: 'haveChild'  // 自定义标识是否还有子节点的字段名称
        },
        cols: [
            {
                field: 'name', title: '服务分类', width: 300, templet: function (d) {
                    var split = d.otherId.split("_");
                    var text = '';
                    let intputStr;
                    //一级分类与服务分类
                    if (split.length == 1) {
                        if (split == d.id) {
                            let serverIn = $.inArray(d.id, json.servCategIds);
                            if (serverIn > -1) {
                                intputStr = '<input type="checkbox" name="serverClassName_' + d.otherId + '" otherId="' + d.otherId + '" lay-filter="serverClassCheck" lay-skin="primary" value="' + d.id + '" title="' + d.name + '" checked>'
                            } else {
                                intputStr = '<input type="checkbox" name="serverClassName_' + d.otherId + '" otherId="' + d.otherId + '" lay-filter="serverClassCheck" lay-skin="primary" value="' + d.id + '" title="' + d.name + '" >'
                            }
                        } else {
                            let serverIn = $.inArray(parseInt(d.otherId), json.servCategIds);
                            let oneclassIn = $.inArray(d.id, json.categOneIds);
                            if (oneclassIn > -1 && serverIn > -1) {
                                intputStr = '<input type="checkbox" name="oneClassName_' + d.otherId + '" otherId="' + d.otherId + '" lay-filter="oneClassCheck" lay-skin="primary" value="' + d.id + '" title="' + d.name + '" checked>'
                            } else {
                                intputStr = '<input type="checkbox" name="oneClassName_' + d.otherId + '" otherId="' + d.otherId + '" lay-filter="oneClassCheck" lay-skin="primary" value="' + d.id + '" title="' + d.name + '" >'
                            }
                        }
                    } else {
                        let tempIds = d.otherId.split("_");
                        let serverIn = $.inArray(parseInt(tempIds[0]), json.servCategIds);
                        let oneclassIn = $.inArray(parseInt(tempIds[1]), json.categOneIds);
                        let twoclassIn = $.inArray(d.id, json.categIds);
                        if (twoclassIn > -1 && oneclassIn > -1 && serverIn > -1) {
                            intputStr = '<input type="checkbox" name="twoClassName_' + d.otherId + '" otherId="' + d.otherId + '" lay-filter="twoClassCheck" lay-skin="primary" value="' + d.id + '" title="' + d.name + '" checked>'
                        } else {
                            intputStr = '<input type="checkbox" name="twoClassName_' + d.otherId + '" otherId="' + d.otherId + '" lay-filter="twoClassCheck" lay-skin="primary" value="' + d.id + '" title="' + d.name + '" >'
                        }
                    }

                    text += intputStr;
                    text += '';
                    return text;
                }
            },
            {field: 'id', title: 'ID', width: 100},
            {field: 'typeName', title: '类型', width: 100},
            {
                field: 'products', title: '服务产品', templet: function (d) {
                    if (d.products) {
                        let text = '<div>';
                        let lineNum = 4;
                        let initnNum = 1;
                        for (let i = 0; i < d.products.length; i++) {
                            let tempIds = d.products[i].otherId.split("_");
                            let serverIn = $.inArray(parseInt(tempIds[0]), json.servCategIds);
                            let oneclassIn = $.inArray(parseInt(tempIds[1]), json.categOneIds);
                            let twoclassIn = $.inArray(parseInt(tempIds[2]), json.categIds);
                            let productesIn = $.inArray(d.products[i].id, json.productIds);
                            let intputStr;
                            if (productesIn > -1 && twoclassIn > -1 && oneclassIn > -1 && serverIn > -1) {
                                intputStr = '<input type="checkbox" name="productName_' + d.products[i].otherId + '" otherId="' + d.products[i].otherId + '" lay-filter="ckState" value="' + d.products[i].id + '" lay-skin="switch" lay-text="' + d.products[i].name + '|' + d.products[i].name + '" checked/>';
                            } else {
                                intputStr = '<input type="checkbox" name="productName_' + d.products[i].otherId + '" otherId="' + d.products[i].otherId + '"  lay-filter="ckState" value="' + d.products[i].id + '" lay-skin="switch" lay-text="' + d.products[i].name + '|' + d.products[i].name + '" />';
                            }
                            if (initnNum == lineNum) {
                                intputStr += '</br>';
                                initnNum = 1;
                            }
                            initnNum++;
                            text += intputStr;
                        }
                        text += '</div>';
                        return text;
                    } else {
                        return "";
                    }
                }
            }
        ],
        reqData: function (data, callback) {
            $.post('/conf/attachment/orderPicture/loadServerClassData.action', function (res) {
                callback(res.data);  // 参数是数组类型
                serverClasscheck = $("input[name^='serverClassName_']:checked");
                oneClasscheck = $("input[name^='oneClassName_']:checked");
                twoClasscheck = $("input[name^='twoClassName_']:checked");
                if (json.param.allProduct == 0) {
                    $("#productButtonDiv").attr("style", "display:block;");
                } else {
                    $("#productButtonDiv").attr("style", "display:none;");
                    serverClasscheck.prop("checked", false);
                    oneClasscheck.prop("checked", false);
                    twoClasscheck.prop("checked", false);
                    form.render();
                }

            });
        }
    });

    let limitProduct = json.param.allProduct | false;
    form.on('switch(chk_status_product)', function (data) {
        let alertDesc;
        if (data.elem.checked) {
            limitProduct = true;
            alertDesc = '是否开通全部产品';
        } else {
            //2是限制
            limitProduct = false;
            alertDesc = '是否关闭全部产品';
        }
        layer.confirm(alertDesc, {
            btn: ['确定', '取消']
        }, function () {
            if (limitProduct) {
                $("#productButtonDiv").attr("style", "display:none;");

                serverClasscheck.prop("checked", false);
                oneClasscheck.prop("checked", false);
                twoClasscheck.prop("checked", false);
                form.render();
            } else {
                $("#productButtonDiv").attr("style", "display:block;");
                serverClasscheck.prop("checked", true);
                oneClasscheck.prop("checked", true);
                twoClasscheck.prop("checked", true);
                form.render();
            }
            layer.msg('保存成功!', {icon: 1});
        }, function () {
            $("#limitProduct").prop("checked", !(data.elem.checked));
            form.render('checkbox');
        });
    });

    form.on('checkbox(serverClassCheck)', function(obj){
        let input=obj.elem;
        let server_id=$(input).attr("value");
        let oneclass;
        let twoclass;
        let twoAllclass=[];
        let peoductClass;
        let peoductAllClass = [];
        //一级分类
        oneclass = $(input).parents().find("input[name=oneClassName_"+server_id+"]");
        oneclass.prop("checked",input.checked);
        if (oneclass.length > 0){
            //二级分类
            oneclass.each(function (index,item) {
                let one_class_id = item.value;
                twoclass = $(input).parents().find("input[name=twoClassName_"+server_id+"_"+one_class_id+"]");
                twoAllclass.push(twoclass);
                twoclass.prop("checked",input.checked);
                if (twoclass.length > 0){
                    //产品分类
                    twoclass.each(function (index, item) {
                        let two_class_id = item.value;
                        peoductClass = $(input).parents().find("input[name=productName_"+server_id+"_"+one_class_id+"_"+two_class_id+"]");
                        peoductAllClass.push(peoductClass);
                        peoductClass.prop("checked",input.checked);
                    })
                }
            })
        }

        //数据集合维护
        if (input.checked){
            //添加服务分类数据
            json.servCategIds.push2(server_id);
            oneclass.each(function (index,item) {
                json.categOneIds.push2(item.value)
            });
            twoAllclass.forEach(function (item, index, arr) {
                item.map(function (idx, ele) {
                    json.categIds.push2($(ele).val())
                });
            });

            peoductAllClass.forEach(function (item, index, arr) {
                item.map(function (idx, ele) {
                    json.productIds.push2($(ele).val())
                });
            });

        } else {
            json.servCategIds.remove(server_id);

            oneclass.each(function (index,item) {
                json.categOneIds.remove(item.value);
            });

            twoAllclass.forEach(function (item, index, arr) {
                item.map(function (idx, ele) {
                    json.categIds.remove($(ele).val())
                });
            });

            peoductAllClass.forEach(function (item, index, arr) {
                item.map(function (idx, ele) {
                    json.productIds.remove($(ele).val())
                });
            });
        }

        form.render();
    });

    //一级分类选择器
    form.on('checkbox(oneClassCheck)', function (obj) {
        let input = obj.elem;
        let otherId = $(input).attr("otherId");
        let one_class_id = $(input).attr("value");
        let twoclass;
        let peoductClass;
        let peoductAllClass = [];
        if (input.checked) {
            //服务分类
            let serverClass = $(input).parents().find("input[name=serverClassName_" + otherId + "]");
            serverClass.prop("checked", input.checked);
        }
        //二级分类
        twoclass = $(input).parents().find("input[name=twoClassName_" + otherId + "_" + one_class_id + "]");
        twoclass.prop("checked", input.checked);
        if (twoclass.length > 0) {
            //产品分类
            twoclass.each(function (index, twoclassData) {
                let two_class_id = twoclassData.value;
                peoductClass = $(input).parents().find("input[name=productName_" + otherId + "_" + one_class_id + "_" + two_class_id + "]");
                peoductAllClass.push(peoductClass);
                peoductClass.prop("checked", input.checked);
            })
        }

        //数据集合维护
        if (input.checked) {
            //添加服务分类数据
            json.servCategIds.push2(otherId);
            json.categOneIds.push2(one_class_id);
            twoclass.each(function (index, item) {
                json.categIds.push2(item.value)
            });

            peoductAllClass.forEach(function (item, index, arr) {
                let arr1 = item.map(function (idx, ele) {
                    json.productIds.push2(parseInt($(ele).val()))
                });
            });
        } else {
            json.categOneIds.remove(one_class_id);
            twoclass.each(function (index, item) {
                json.categIds.remove(item.value);
            });
            peoductAllClass.forEach(function (item, index, arr) {
                item.map(function (idx, ele) {
                    json.productIds.remove($(ele).val())
                });
            });
        }
        form.render();
    });

    //二级分类选择器
    form.on('checkbox(twoClassCheck)', function (obj) {
        let input = obj.elem;
        let otherId = $(input).attr("otherId");
        let tempIds = otherId.split("_");
        let two_class_id = $(input).attr("value");
        let oneclass;
        let serverClass;
        if (input.checked) {
            //一级分类
            oneclass = $(input).parents().find("input[name=oneClassName_" + tempIds[0] + "][value=" + tempIds[1] + "]");
            oneclass.prop("checked", input.checked);

            //服务分类
            serverClass = $(input).parents().find("input[name=serverClassName_" + tempIds[0] + "]");
            serverClass.prop("checked", input.checked);

        }

        //产品分类
        let peoductClass = $(input).parents().find("input[name=productName_" + otherId + "_" + two_class_id + "]");
        peoductClass.prop("checked", input.checked);

        //数据集合维护
        if (input.checked) {
            //添加服务分类数据
            json.servCategIds.push2(tempIds[0]);
            json.categOneIds.push2(tempIds[1]);
            json.categIds.push2(two_class_id);
            peoductClass.each(function (index, item) {
                json.productIds.push2(parseInt(item.value))
            });
        } else {
            json.categIds.remove(two_class_id);
            peoductClass.each(function (index, item) {
                json.productIds.remove(item.value);
            });
        }
        form.render();
    });

    // 启用/停用（单个）
    form.on('switch(ckState)', function (obj) {
        let input = obj.elem;
        let checked = obj.elem.checked;
        let otherId = $(input).attr("otherId");
        let tempIds = otherId.split("_");
        let serviceCategoryId = tempIds[0];
        let levelOneId = tempIds[1];
        let levelTwoId = tempIds[2];
        let levelOneTR = $(input).parent().parent().parent().parent().parent();//一级分类TR
        let tbody = $(levelOneTR).parent();//表格的tbody
        let levelTwoCheckBox = $(tbody).find("input[name=twoClassName_" + serviceCategoryId + "_" + levelOneId + "][value=" + levelTwoId + "]")//一级分类的checkbox;
        let levelOneCheckBox = $(tbody).find("input[name=oneClassName_" + serviceCategoryId + "][value=" + levelOneId + "]");//二级分类的checkbox
        let levelServiceCategoryCheckBox = $(tbody).find("input[name=serverClassName_" + serviceCategoryId + "]");//服务分类的checkbox
        if (checked) {
            $(levelTwoCheckBox).prop("checked", true);
            $(levelOneCheckBox).prop("checked", true);
            $(levelServiceCategoryCheckBox).prop("checked", true);
            json.productIds.push(parseInt(obj.elem.value));
            json.categOneIds.push(levelOneId);
            json.categIds.push(levelTwoId);
            json.servCategIds.push(serviceCategoryId);
        } else {
            json.productIds.remove(obj.elem.value);
        }
        form.render();
    });

    form.on('submit(order_picture_product-submit)', function (data) {

        if (json.productIds.length === 0 && !limitProduct) {
            layer.msg("请选择产品", {icon: 2});
            return false;
        }
        if (limitProduct) {
            submitParam.allProduct = limitProduct
            submitParam.productIds = [];
        } else {
            submitParam.allProduct = false
            submitParam.productIds = json.productIds
        }
        submitParam.rephotograph = submitParam.rephotograph === "true";
        submitParam.orderDetailShow = submitParam.orderDetailShow === "true";
        console.log("submitParam", submitParam)
        $("#order_picture_product-submit").addClass("layui-btn layui-btn-disabled").prop("disabled", true);
        $('#order_picture_product-submit').attr("disabled", true);
        $.ajax({
            type: "POST",
            contentType: "application/json;charset=UTF-8",
            url: "/conf/attachment/orderPicture/save.action",
            data: JSON.stringify(submitParam),
            dataType: 'json',
            success: function (res) {
                if (res.status == 200) {
                    // 清除所有页面缓存
                    window.sessionStorage.removeItem("switch_allChannel")
                    window.sessionStorage.removeItem("list_channel_table_data")
                    window.sessionStorage.removeItem("cooperation_checked_row")
                    $('#order_picture_product-submit').attr("disabled", false);
                    $("#order_picture_product-submit").removeClass("layui-btn-disabled").prop("disabled", false);
                    layer.msg('保存成功!', {icon: 1});
                    location.href = "/conf/attachment/orderPicture/list.action"
                } else {
                    $('#order_picture_product-submit').attr("disabled", false);
                    $("#order_picture_product-submit").removeClass("layui-btn-disabled").prop("disabled", false);
                    layer.msg(res.message, {icon: 2});
                }
            }
        });
        $('#order_picture_product-submit').attr("disabled", false);
        $("#order_picture_product-submit").removeClass("layui-btn-disabled").prop("disabled", false);
        return false;
    });

    Array.prototype.push2 = function (val) {
        let index = this.indexOf(val);
        if (index < 0) {
            this.push(val);
        }
    };
    Array.prototype.indexOf = function (val) {
        for (let i = 0; i < this.length; i++) {
            if (this[i] == val) return i;
        }
        return -1;
    };
    Array.prototype.remove = function (val) {
        let index = this.indexOf(val);
        if (index > -1) {
            this.splice(index, 1);
        }
    };
    /*********************************************基本，合作，城市，产品，结束***********************************************************/


    $('.pre').click(function () {
        step.pre('#stepForm');
        $('html , body').animate({scrollTop: 0}, null);
        return false;
    });
    exports('oms_conf_attachment_orderPicture_new_detail', {});
})
;
